package net.dreamlu.system.web;

import lombok.AllArgsConstructor;

import net.dreamlu.common.base.BaseController;
import net.dreamlu.common.result.EasyPage;
import net.dreamlu.common.result.PageVO;

import net.dreamlu.system.model.VlogCensor;
import net.dreamlu.system.service.IVlogCensorService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/vlogCensor")
@AllArgsConstructor
public class VlogCensorController extends BaseController {
//、
	@Autowired
	private IVlogCensorService vlogCensorService;

	@GetMapping("/manager")
	public String manager() {
		return "system/vlogCensor/vlogCensorList";
	}

	@PostMapping("/dataGrid")
	@ResponseBody
	public EasyPage<VlogCensor> dataGrid(VlogCensor vlogCensor, PageVO pageVO) {
		// 分页查询
		EasyPage<VlogCensor> easyPage = vlogCensorService.selectPage(vlogCensor, pageVO);
		return easyPage;
	}

	@PostMapping("add")
	@ResponseBody
	public Object add(VlogCensor vlogCensor){

		Date date = new Date();
		vlogCensor.setCreateTime(date);
		vlogCensor.setUpdateTime(date);

		Byte b = 0;
		vlogCensor.setVideoStatus(b);
		vlogCensor.setTextStatus(b);
		vlogCensor.setStatus(b);
		vlogCensor.setAuditor("admin");

		boolean save = vlogCensorService.save(vlogCensor);
		return status(save);
	}

	/**
	 * 编辑的page
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping("editPage")
	public String editPage(Integer id, Model model){
		VlogCensor byId = vlogCensorService.getById(id);
		model.addAttribute("vlogCensor",byId);
		//跳转到编辑的html
		return "system/vlogCensor/vlogCensorEdit";
	}

	@PostMapping("edit")
	@ResponseBody
	public Object edit(VlogCensor vlogCensor){

		Date date = new Date();
		vlogCensor.setUpdateTime(date);

		boolean update = vlogCensorService.updateById(vlogCensor);

		return status(update);
	}


	@PostMapping("delete")
	@ResponseBody
	public Object delete(Integer id){

		boolean delete = vlogCensorService.removeById(id);
		return status(delete);
	}

}
